home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Games / Game Sample Code / ZAM 1.0a13 / GameSource / SlamPixels.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  5.3 KB  |  225 lines  |  [TEXT/KAHL]

  1.  
  2. #include "SlamPixels.proto.h"
  3.  
  4.  
  5. typedef struct {
  6.     char        *packedImage;
  7.     short        *code;
  8. } pixiZAM;
  9.  
  10.  
  11. void CIconToPixiZAM(CIconHandle cicn, pixiZam *pz)
  12. {
  13.     char    *srcImagePtr;
  14.     char    *maskImagePtr;
  15.     char    *dstImagePtr;
  16.     short    *dstCodePtr;
  17.     long    imageMemSize;
  18.     long    imageCodeSize;
  19.     
  20.     srcImagePtr = (**cicn).iconPMap.baseAddr;
  21.     maskImagePtr = (**cicn).iconPMap.maskImagePtr;
  22.  
  23.     imageMemSize = ((**cicn).iconPMap.bounds.bottom - 
  24.                 (**cicn).iconPMap.bounds.top) * (**cicn).iconPMap.rowBytes;
  25.                 
  26.     dstImagePtr = NewPtrClear(imageMemSize);
  27.     
  28.     imageCodeSize = (**cicn).iconPMap.bounds.bottom - 
  29.                 (**cicn).iconPMap.bounds.top) * (**cicn).iconPMap.rowBytes / 2);
  30.                 
  31.     dstCodePtr = NewPtrClear();
  32.     
  33.     
  34. }
  35.  
  36. void BlitPixie(PixMapHandle srcPixMapH, PixMapHandle dstPixMapH, Rect *pixRect)
  37. {
  38.     long *srcPixP;                                        // pointer to video memory
  39.     long *dstPixP;                                        // pointer to video memory
  40.     register long numRowsToCopy;            // rows we are going to copy
  41.     long srcStripRowBytes;                        // to clear high bit of rowbytes
  42.     long dstStripRowBytes;                        // to clear high bit of rowbytes
  43.     register long srcRowLongsOffset;    // rowBytes converted to long
  44.     register long dstRowLongsOffset;    // rowBytes converted to long
  45.     long numRowLongs;                                    // number of long words per row
  46.     Rect blitRect;                                        // area to blit
  47.     char mmuMode;                                            // 32-bit mode required
  48.  
  49.         // make a local copy so we can make some adjustments
  50.     blitRect = *pixRect;
  51.  
  52.         // long word align the left edge
  53.     blitRect.left &= ~3;
  54.  
  55.         // is the right edge long word aligned?
  56.     if (blitRect.right & 3)
  57.         {
  58.             // long word align the right edge
  59.         blitRect.right &= ~3;        // we could combine these into one line but THINK C
  60.         blitRect.right += 4;        // generates half as many instructions this way
  61.         }
  62.  
  63.         // clip off the top so we dont write into random memory
  64.     if (blitRect.top < (**dstPixMapH).bounds.top)
  65.         {
  66.         blitRect.top = (**dstPixMapH).bounds.top;
  67.  
  68.         if (blitRect.top >= blitRect.bottom)
  69.             {
  70.             return;
  71.             }
  72.         }
  73.  
  74.         // clip off the left so we dont write into random memory
  75.     if (blitRect.left < (**dstPixMapH).bounds.left)
  76.         {
  77.         blitRect.left = (**dstPixMapH).bounds.left;
  78.  
  79.         if (blitRect.left >= blitRect.right)
  80.             {
  81.             return;
  82.             }
  83.         }
  84.  
  85.         // clip off the bottom so we dont write into random memory
  86.     if (blitRect.bottom > (**dstPixMapH).bounds.bottom)
  87.         {
  88.         blitRect.bottom = (**dstPixMapH).bounds.bottom;
  89.  
  90.         if (blitRect.bottom <= blitRect.top)
  91.             {
  92.             return;
  93.             }
  94.         }
  95.  
  96.         // clip off the right so we dont write into random memory
  97.     if (blitRect.right > (**dstPixMapH).bounds.right)
  98.         {
  99.         blitRect.right = (**dstPixMapH).bounds.right;
  100.  
  101.         if (blitRect.right <= blitRect.left)
  102.             {
  103.             return;
  104.             }
  105.         }
  106.  
  107.         // high bit of pixMap rowBytes must be cleared
  108.     srcStripRowBytes = (**srcPixMapH).rowBytes & 0x7FFF;
  109.  
  110.         // high bit of pixMap rowBytes must be cleared
  111.     dstStripRowBytes = (**dstPixMapH).rowBytes & 0x7FFF;
  112.  
  113.         // calculate the address of the first byte of the source
  114.     srcPixP = (long *)(GetPixBaseAddr(srcPixMapH) + ((long)srcStripRowBytes * blitRect.top) + blitRect.left);
  115.  
  116.         // calculate the address of the first byte of the destination
  117.     dstPixP = (long *)(GetPixBaseAddr(dstPixMapH) + ((long)dstStripRowBytes * blitRect.top) + blitRect.left);
  118.  
  119.  
  120.         // calculate the number of rows to copy
  121.     numRowsToCopy = blitRect.bottom - blitRect.top;
  122.  
  123.         // calculate the number of long words in a row
  124.     numRowLongs = (blitRect.right - blitRect.left) >> 2;
  125.  
  126.         // calculate the long word offset from the end of one row to the start of the next
  127.     srcRowLongsOffset = (srcStripRowBytes >> 2) - numRowLongs;
  128.  
  129.         // calculate the long word offset from the end of one row to the start of the next
  130.     dstRowLongsOffset = (dstStripRowBytes >> 2) - numRowLongs;
  131.  
  132.         // change to 32-bit addressing mode to access video memory
  133.         // the previous addressing mode is returned in mmuMode for restoring later
  134.     mmuMode = true32b;
  135.     SwapMMUMode(&mmuMode);
  136.  
  137.         // blit the pixels
  138.     do
  139.         {
  140.  
  141.         // this is so sick, but it works!
  142.     switch (numRowLongs)
  143.         {
  144.         case 32:
  145.             *dstPixP++ = *srcPixP++;
  146.         case 31:
  147.             *dstPixP++ = *srcPixP++;
  148.         case 30:
  149.             *dstPixP++ = *srcPixP++;
  150.         case 29:
  151.             *dstPixP++ = *srcPixP++;
  152.         case 28:
  153.             *dstPixP++ = *srcPixP++;
  154.         case 27:
  155.             *dstPixP++ = *srcPixP++;
  156.         case 26:
  157.             *dstPixP++ = *srcPixP++;
  158.         case 25:
  159.             *dstPixP++ = *srcPixP++;
  160.         case 24:
  161.             *dstPixP++ = *srcPixP++;
  162.         case 23:
  163.             *dstPixP++ = *srcPixP++;
  164.         case 22:
  165.             *dstPixP++ = *srcPixP++;
  166.         case 21:
  167.             *dstPixP++ = *srcPixP++;
  168.         case 20:
  169.             *dstPixP++ = *srcPixP++;
  170.         case 19:
  171.             *dstPixP++ = *srcPixP++;
  172.         case 18:
  173.             *dstPixP++ = *srcPixP++;
  174.         case 17:
  175.             *dstPixP++ = *srcPixP++;
  176.         case 16:
  177.             *dstPixP++ = *srcPixP++;
  178.         case 15:
  179.             *dstPixP++ = *srcPixP++;
  180.         case 14:
  181.             *dstPixP++ = *srcPixP++;
  182.         case 13:
  183.             *dstPixP++ = *srcPixP++;
  184.         case 12:
  185.             *dstPixP++ = *srcPixP++;
  186.         case 11:
  187.             *dstPixP++ = *srcPixP++;
  188.         case 10:
  189.             *dstPixP++ = *srcPixP++;
  190.         case 9:
  191.             *dstPixP++ = *srcPixP++;
  192.         case 8:
  193.             *dstPixP++ = *srcPixP++;
  194.         case 7:
  195.             *dstPixP++ = *srcPixP++;
  196.         case 6:
  197.             *dstPixP++ = *srcPixP++;
  198.         case 5:
  199.             *dstPixP++ = *srcPixP++;
  200.         case 4:
  201.             *dstPixP++ = *srcPixP++;
  202.         case 3:
  203.             *dstPixP++ = *srcPixP++;
  204.         case 2:
  205.             *dstPixP++ = *srcPixP++;
  206.         default:
  207.             *dstPixP++ = *srcPixP++;
  208.         }
  209.  
  210.             // bump to start of next row
  211.         srcPixP += srcRowLongsOffset;
  212.         dstPixP += dstRowLongsOffset;
  213.         } while (--numRowsToCopy);
  214.  
  215.         // restore addressing mode back to what it was
  216.     SwapMMUMode(&mmuMode);
  217.     }
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.